import * as types from './mutation-types'
import iView from "iview";

export default {
  [types.USER_SING_IN](state, user){
    state.jwt = user.jwt
    state.name = user.name
  },
  [types.USER_SIGN_OUT](state){
    state.jwt = ''
    state.name = ''
  },
  [types.SET_MENUS](state, menus){
    state.menus = menus
  },
  [types.SET_CURRENT_MAIN_MENU](state, menu){
    state.currentMainMenu = menu
  },
  [types.SOCKET_ONOPEN](state, event){
    state.websocket.isConnected = true
    state.websocket.$socket = event.currentTarget
  },
  [types.SOCKET_ONCLOSE](state, event){
    console.log(event)
    state.websocket.isConnected = false
  },
  [types.SOCKET_ONERROR](state, event){
    iView.Notice.warning({
      title: '服务端暂未开启Socket服务',
      desc: '',
      duration: 4
    })
  },
  [types.SOCKET_ONMESSAGE](state, message){
    // state.websocket.$socket.send('♥')
    if(message.act === 'query'){
      state.mapMessages = message.list
      console.log(state.mapMessages)
      return true
    }
    // state.websocket.$socket.send('♥')
    // if (message.act === '♥') {
    //   state.websocket.$socket.send('♥')
    // }
    // if (message.act === 'AskUserInfo') {
    //   state.websocket.$socket.sendObj({
    //     act: 'reportUserInfo',
    //     data: {
    //       fd: message.data.fd,
    //       jwt: state.jwt
    //     }
    //   })
    // }
    // if (message.act === 'ShowMyReplay') {
    //   let session = message.data.session
    //   let data = {
    //     replay: 0,
    //     type: 'text',
    //     content: message.data.content
    //   }
    //   // let ret = state.serviceMessages.some((k) => {
    //   //   if (k === session) {
    //   //     state.serviceMessages[k].push(data)
    //   //     return true
    //   //   }
    //   // })
    //   // if (!ret) {
    //   //   state.serviceMessages[session] = []
    //   //
    //   // }
    //   if (state.serviceMessages[session] === undefined) {
    //     state.serviceMessages[session] = []
    //   }
    //   state.serviceMessages[session].push(data)
    //   console.log(state.serviceMessages)
    // }
    // if (message.act === 'SendMessage') {
    //   iView.Notice.success({
    //     title: '您有新的消息',
    //     desc: '',
    //     duration: 4
    //   })
    // }
  },
  [types.SOCKET_RECONNECT](state, event){
    console.log(event)
  },
  [types.SOCKET_RECONNECT_ERROR](state){
    iView.Notice.warning({
      title: '服务端暂未开启Socket服务',
      desc: '',
      duration: 4
    })
  },
  [types.SET_COMMONS_STATE](state, list){
    state.commonsState = list
  }
}
